/*调查章节js*/
//选项是否有图片
function optionImgIsNull(xuanzheStr) {
	if (!isEmpty(xuanzheStr)) {
		if (xuanzheStr.toString().indexOf("img") > 0) {//题目选项中带有图片
			var ImgArr = RegularGetImgSrcArr(xuanzheStr);
			var words = "";
			if (!isEmpty(htmlspecialchars_decode(xuanzheStr))) {
				words = htmlspecialchars_decode(xuanzheStr);
			} else {
				words = '<br>';
			}
			if (ImgArr.length > 1) {//图片张数超过1张
				var ImgStr1 = "";
				for (var i = 0; i < ImgArr.length; i++) {
					var imgstr2 = PicDomainName(ImgArr[i], 0);
					var imgstr3 = '<div class="option_video_div"  imgUrl="' + ImgArr[i] + '" onclick="showImg(this)">' + '<img class="xuanzeImgDiv" src="' + imgstr2 + '"  imgUrl="' + ImgArr[i] + '" alt="" >' + '</div>';
					ImgStr1 = ImgStr1 + imgstr3;
				}
				return words + ImgStr1;
			} else {
				var xuanzheImgstr = PicDomainName(ImgArr[0], 0);
				return words + '<div class="option_video_div"  imgUrl="' + ImgArr[0] + '" onclick="showImg(this)">' + '<img class="xuanzeImgDiv" src="' + xuanzheImgstr + '"  imgUrl="' + ImgArr[0] + '" alt="" >' + '</div>';
			}

		} else {
			return '<label>' + htmlspecialchars_decode(xuanzheStr);
			+'</label>';
		}
	} else {
		return '';
	}
}

//题目是否有图片
function questionsImgIsNull(questionsStr) {
	if (!isEmpty(questionsStr)) {
		if (questionsStr.indexOf("img") > 0) {
			var ImgArr = RegularGetImgSrcArr(questionsStr);
			var words = "";
			if (!isEmpty(htmlspecialchars_decode(questionsStr))) {
				words = htmlspecialchars_decode(questionsStr);
			} else {
				words = '<br>';
			}
			if (ImgArr.length > 1) {//图片张数超过1张
				var ImgStr1 = "";
				for (var i = 0; i < ImgArr.length; i++) {
					var imgstr2 = PicDomainName(ImgArr[i], 320);
					var imgstr3 = '<img class="questionItemImgDiv"  src="' + imgstr2 + '" imgUrl="' + ImgArr[i] + '"  alt="" onclick="showImg(this)">';
					ImgStr1 = ImgStr1 + imgstr3;
				}
				return words + ImgStr1;
			} else {
				var questionsItemImgstr = PicDomainName(ImgArr[0], 320);
				return words + '<img class="questionItemImgDiv"  src="' + questionsItemImgstr + '" imgUrl="' + ImgArr[0] + '"  alt="" onclick="showImg(this)">';
			}
		} else {
			return htmlspecialchars_decode(questionsStr);
		}
	} else {
		return '';
	}
}

//正则获取img标签中的src地址
function RegularGetImgSrcArr(str) {
	var srcArr = new Array();
	var imgReg = /<img.*?(?:>|\/>)/gi;
	//匹配src属性
	var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
	var arr = str.match(imgReg);
	for (var i = 0; i < arr.length; i++) {
		var src = arr[i].match(srcReg);
		srcArr.push(getpicurl(src[1]));
	}
	return srcArr;
}

//正则获取p标签中的url地址
function RegularGetVideoUrlArr(str) {
	var UrlArr = new Array();
	var reg = /<p.*?class[ \t]*=[ \t]*"edui-video-resource".*?>.*?<\/p>/ig;
	//匹配url属性
	var urlReg = /url=[\'\"]?([^\'\"]*)[\'\"]?/i;
	var arr = str.match(reg);
	for (var i = 0; i < arr.length; i++) {
		var src = arr[i].match(urlReg);
		UrlArr.push((src[1]));
	}
	return UrlArr;
}

//正则获取p标签中的url地址
function RegularGetVideotwoUrlArr(str) {
	var UrlArr = new Array();

	if (str.indexOf("src") > 0 && str.indexOf("video") > 0) {

		var reg = /<source.*?(?:>|\/>)/gi;
		//匹配url属性
		var urlReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
		var arr = str.match(reg);
		for (var i = 0; i < arr.length; i++) {
			var src = arr[i].match(urlReg);
			UrlArr.push((src[1]));
		}
	} else {

	}
	return UrlArr;
}

//展示图片
function showImg(obj) {
	openLocalFile(obj.attributes["imgUrl"].nodeValue)
}

//播放视频
function toPlayVideo(obj) {
	var url = obj.attributes["video-url"].nodeValue;
	if (!isEmpty(url)) {
		api.openWin({useWKWebView:true,
			name : 'BaiDuWebVideo',
			url : '../Study/BaiDuWebVideo.html',
			pageParam : {
				title : '',
				url : url,
				token : '',
			},
			slidBackEnabled : false,
			reload : true
		});
	} else {
		ShowToast('暂无视频')
	}
}